package lv.ante.xwiki.filters;

import java.io.FilterWriter;
import java.io.IOException;
import java.io.Writer;

public class BuferizedFilterWriter extends FilterWriter {
       private static final int EOF = -1;

       private String delimiter;

       private StringBuffer buffer = new StringBuffer();

       private int count = 0;

       public BuferizedFilterWriter(Writer output, String delimiter) {
               super(output);
               this.delimiter = delimiter;
       }

       public void write(int c) throws IOException {
               if (c == EOF) {
                       super.write(buffer.toString());
                       super.write(c);
               } else {
                       buffer.append((char) c);
               }
       }

       public void write(char cbuf[], int off, int len) throws IOException {
               if (len > 0) {
                       char[] temp = new char[len];
                       for (int i = 0; i < len; i++) {
                               temp[i] = cbuf[off + i];
                       }
                       buffer.append(new String(temp));
               }
       }

       public void write(String str, int off, int len) throws IOException {
               write(str.toCharArray(), off, len);
       }
}

